import {
	createRouter,
	createWebHistory
} from 'vue-router'
import {
	useStore
} from 'vuex'

const router = createRouter({
	history: createWebHistory(),
	routes: [{
			path: '/',
			redirect: '/Login' // 将根路径重定向到登录页面
		},
		//登录
		{
			path: '/Login',
			name: 'Login',
			component: () => import('../Login/Login.vue')
		},
		//概况
		{
			path: '/GaiKuang',
			name: 'GaiKuang',
			meta: {
				title: '概况',
				requireAuth: true // 需要认证
			},
			component: () => import('../GaiKuang/GaiKuang.vue')
		},
		//前台
		{
			path: '/QianTai',
			name: 'QianTai',
			meta: {
				title: '前台',
				requireAuth: true // 需要认证
			},
			component: () => import('../QianTai/QianTaiList.vue')
		},
		//房屋住户
		{
			path: '/House',
			name: 'House', // 父级组件，你需要定义一个包裹子路由的父组件
			children: [{
					//房屋管理
					path: 'HouseList',
					name: 'HouseList',
					meta: {
						title: '房屋管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../House/HouseList.vue')
				},
				{
					//区域管理
					path: 'Regional',
					name: 'Regional',
					meta: {
						title: '区域管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../House/Regional.vue')
				},
				{
					//住户管理
					path: 'HosingList',
					name: 'HosingList',
					meta: {
						title: '住户管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../House/HosingList.vue')
				}
			]
		},
		//房屋新增
		{
			path: '/AddHouse',
			name: 'AddHouse',
			meta: {
				title: '房屋新增',
				requireAuth: true // 需要认证
			},
			component: () => import('../House/AddHouse.vue')
		},
		//添加住户
		{
			path: '/AddHousehold',
			name: 'AddHousehold',
			meta: {
				title: '住户新增',
				requireAuth: true // 需要认证
			},
			component: () => import('../House/AddHousehold.vue')
		},
		//修改房屋信息
		{
			path: '/updateHouse',
			name: 'updateHouse',
			meta: {
				title: '住户新增',
				requireAuth: true // 需要认证
			},
			component: () => import('../House/updateHouse.vue'),
			props: true
		},
		//区域管理
		//车位车辆
		{
			path: '/ParkCar',
			name: 'ParkCar',
			children: [{
					//车位管理
					path: 'SpaceList',
					name: 'SpaceList',
					meta: {
						title: '车位管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../ParkCar/SpaceList.vue')
				},
				{
					//车场管理
					path: 'ParkLotList',
					name: 'ParkLotList',
					meta: {
						title: '车场管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../ParkCar/ParkLotList.vue')
				},
				{
					//车辆管理
					path: 'CarList',
					name: 'CarList',
					meta: {
						title: '车位管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../ParkCar/CarList.vue')
				},

				{
					//车辆审核
					path: 'CarReview',
					name: 'CarReview',
					meta: {
						title: '车辆审核',
						requireAuth: true // 需要认证
					},
					component: () => import('../ParkCar/CarReview.vue')
				},
				{
					//出入记录
					path: 'CarOutList',
					name: 'CarOutList',
					meta: {
						title: '出入记录',
						requireAuth: true // 需要认证
					},
					component: () => import('../ParkCar/CarOutList.vue')
				}
			]
		},
		{
			//车位添加
			path: '/AddCarwei',
			name: 'AddCarwei',
			meta: {
				title: '添加车位',
				requireAuth: true // 需要认证
			},
			component: () => import('../ParkCar/AddCarwei.vue')
		},
		{
			//车辆添加
			path: '/AddCar',
			name: 'AddCar',
			meta: {
				title: '添加车辆',
				requireAuth: true // 需要认证
			},
			component: () => import('../ParkCar/AddCar.vue')
		},
		//费用管理
		{
			path: '/FeiYong',
			name: 'FeiYong',
			children: [{
					//费用列表
					path: 'CostList',
					name: 'CostList',
					meta: {
						title: '费用列表',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/CostList.vue')
				},
				{
					//生成列表
					path: 'AddCost',
					name: 'AddCost',
					meta: {
						title: '生成列表',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/AddCost.vue')
				},
				{
					//仪表管理
					path: 'MeterList',
					name: 'MeterList',
					meta: {
						title: '仪表管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/MeterList.vue')
				},
				{
					//收支管理
					path: 'ShouZhiList',
					name: 'ShouZhiList',
					meta: {
						title: '收支管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/ShouZhiList.vue')
				},
				{
					//催缴管理
					path: 'ZiChanList',
					name: 'ZiChanList',
					meta: {
						title: '催缴管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/ZiChanList.vue')
				},
				{
					//收退款记录
					path: 'ShouKuanList',
					name: 'ShouKuanList',
					meta: {
						title: '收退款记录',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/ShouKuanList.vue')
				},
				{
					//交易记录
					path: 'JiaoYiJLList',
					name: 'JiaoYiJLList',
					meta: {
						title: '交易记录',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/JiaoYiJLList.vue')
				},
				{
					//收银对账
					path: 'CaiWuDuiZhang',
					name: 'CaiWuDuiZhang',
					meta: {
						title: '收银对账',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/CaiWuDuiZhang.vue')
				},
				{
					//计费项目
					path: 'JiFeiXiangMu',
					name: 'JiFeiXiangMu',
					meta: {
						title: '计费项目',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/JiFeiXiangMu.vue')
				},
				{
					//预存管理
					path: 'YuCunList',
					name: 'YuCunList',
					meta: {
						title: '预存管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/YuCunList.vue')
				},
				{
					//创建费用计费项目
					path: 'chuangJianJiFeiXiangMu',
					name: 'chuangJianJiFeiXiangMu',
					meta: {
						title: '创建费用计费项目',
						requireAuth: true // 需要认证
					},
					component: () => import('../FeiYong/chuangJianJiFeiXiangMu.vue')
				}
			]
		},
		//工单管理
		{
			path: '/WorkOrder',
			name: 'WorkOrder', // 父级组件，你需要定义一个包裹子路由的父组件
			children: [{
					//全部工单
					path: 'GongDanList',
					name: 'GongDanList',
					meta: {
						title: '所有工单',
						requireAuth: true // 需要认证
					},
					component: () => import('../WorkOrder/GongDanList.vue')
				},
				{
					//我的工单
					path: 'MyGongDan',
					name: 'MyGongDan',
					meta: {
						title: '我的工单',
						requireAuth: true // 需要认证
					},
					component: () => import('../WorkOrder/MyGongDan.vue')
				},
				{
					//住户报修
					path: 'BaoXiuList',
					name: 'BaoXiuList',
					meta: {
						title: '住户报修',
						requireAuth: true // 需要认证
					},
					component: () => import('../WorkOrder/BaoXiuList.vue')
				},
				{
					//住户投诉
					path: 'TouSuList',
					name: 'TouSuList',
					meta: {
						title: '住户投诉',
						requireAuth: true // 需要认证
					},
					component: () => import('../WorkOrder/TouSuList.vue')
				},
				{
					//内部创建
					path: 'NeiBuCJ',
					name: 'NeiBuCJ',
					meta: {
						title: '内部创建',
						requireAuth: true // 需要认证
					},
					component: () => import('../WorkOrder/NeiBuCJ.vue')
				},
				{
					//费用催缴
					path: 'CuiJiaoList',
					name: 'CuiJiaoList',
					meta: {
						title: '费用催缴',
						requireAuth: true // 需要认证
					},
					component: () => import('../WorkOrder/CuiJiaoList.vue')
				},
				{
					//工单详情
					path: "GongDanDetail",
					name: 'GongDanDetail',
					meta: {
						title: '工单详情',
						requireAuth: true // 需要认证
					},
					component: () => import('../WorkOrder/GongDanDetail.vue')
				}
			]
		},
		//租赁管理
		{
			path: '/Lease',
			name: 'Lease',
			children: [{
					//车位租赁
					path: 'CarParkLease',
					name: 'CarParkLease',
					meta: {
						title: '车位租赁',
						requireAuth: true // 需要认证
					},
					component: () => import('../Lease/CarParkLease.vue')
				},
				{
					//房屋租赁
					path: 'HouseLease',
					name: 'HouseLease',
					meta: {
						title: '房屋租赁',
						requireAuth: true // 需要认证
					},
					component: () => import('../Lease/HouseLease.vue')
				},
				{
					//车辆停车卡
					path: 'CarStopCard',
					name: 'CarStopCard',
					meta: {
						title: '车辆停车卡',
						requireAuth: true // 需要认证
					},
					component: () => import('../Lease/CarStopCard.vue')
				}
			]
		},
		//数据报表
		{
			path: '/ShuJuBaoBiao',
			name: 'ShuJuBaoBiao',
			meta: {
				title: '数据报表',
				requireAuth: true // 需要认证
			},
			component: () => import('../DataReport/ShuJuBaoBiao.vue')

		},
		{
			//费用报表
			path: '/ExpenseReports',
			name: 'ExpenseReports',
			meta: {
				title: '费用统计',
				requireAuth: true // 需要认证
			},
			component: () => import('../DataReport/ExpenseReports.vue')

		},
		{
			//费用报表
			path: '/HouseBao',
			name: 'HouseBao',
			meta: {
				title: '房屋报表',
				requireAuth: true // 需要认证
			},
			component: () => import('../DataReport/HouseBao.vue')

		},
		{
			//欠费报表
			path: '/Arrears',
			name: 'Arrears',
			meta: {
				title: '欠费统计',
				requireAuth: true // 需要认证
			},
			component: () => import('../DataReport/Arrears.vue')

		},
		{
			//按月出账
			path: '/MonthlyBasis',
			name: 'MonthlyBasis',
			meta: {
				title: '按月出账',
				requireAuth: true // 需要认证
			},
			component: () => import('../DataReport/MonthlyBasis.vue')

		},

		{
			//按月出账
			path: '/Collection',
			name: 'Collection',
			meta: {
				title: '收款日报',
				requireAuth: true // 需要认证
			},
			component: () => import('../DataReport/Collection.vue')

		},
		//全局设置
		{
			path: '/GlobalSettings',
			name: 'GlobalSettings',
			children: [{
					//员工管理
					path: 'EmpList',
					name: 'EmpList',
					meta: {
						title: '员工管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../GlobalSettings/EmpList.vue')
				},
				{
					//角色管理
					path: 'JueSeList',
					name: 'JueSeList',
					meta: {
						title: '角色管理',
						requireAuth: true // 需要认证
					},
					component: () => import('../GlobalSettings/JueSeList.vue')
				},
				{
					//添加员工
					path: 'AddEmp',
					name: 'AddEmp',
					meta: {
						title: '添加员工',
						requireAuth: true // 需要认证
					},
					component: () => import('../GlobalSettings/AddEmp.vue')
				},
				{
					//修改员工
					path: 'UpdEmp',
					name: 'UpdEmp',
					meta: {
						title: '修改员工',
						requireAuth: true // 需要认证
					},
					component: () => import('../GlobalSettings/UpdEmp.vue')
				},
				// 处理未定义路径
				{
					path: '/:pathMatch(.*)*', // 通配符路径匹配
					redirect: '/Login' // 重定向到登录页面
				}
			]
		}
	]
})
// 添加全局路由守卫
router.beforeEach((to, from, next) => {
	const store = useStore()
	if (to.meta.requireAuth && !store.state.isAuthenticated) {
		next('/Login')
	} else {
		next()
	}
})
export default router;